package com.xu.collectionTest;

import java.util.ArrayList;

/**
 * ArrayList 线程不安全  错误实例
 *    解决方案 使用Vector  VectorTest.class
 * @author xudenghui
 * @create 2023-02-02 17:13
 **/
public class ArrayListMultiThread {

    static  ArrayList<Integer> a1 = new ArrayList<Integer>(10);

    public static  class AddThread implements  Runnable{

        @Override
        public void run() {
            for (int i = 0; i<1000000; i++){
                a1.add(i);
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new AddThread());
        Thread t2 = new Thread(new AddThread());
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(a1.size());

    }
}
